<?php
namespace app\thread\controller;
use app\thread\model\Thread;
use org\util\HtmlPage;
use think\Controller;
use think\Request;
class Search extends Controller {
    function search(){
        $kw=input('get.kw');
        $data['p']=!input('p')?1:input('p');
        $data['total']=Thread::where('title','like',"%$kw%")->count();
        $data['limit']=20;
        $data['method']="ajax";
        $data['page_start']=($data['p']-1)*$data['limit'];
        $data['js_method']="search";
        $request=Request::instance();
        $data['url']=$request->baseUrl()."?kw=".$kw."&p=";
        //return $data['url'];
        $thread['content']=Thread::where('title','like',"%$kw%")->limit($data['page_start'],$data['limit'])->order('last_time','desc')->select();
        //var_dump($result);
        //$thread['content']=str_replace($kw,"这是关键字",$result);
        $page_banner=new HtmlPage($data);
        $thread['banner']=$page_banner->banner_list();
        //$m_id_name=Db::name('section')->where('id',$m_id)->value('name');
        $tou="<p><a href=\"/forum/index.php\" class=\"a1\"><font color='#ff8800'>『返回首页』</font></a></p>";
        $thread['head_list']=$tou;
        $thread['total']=$data['total'];
        //return $thread['total'];
        $this->assign("thread_context",$thread['content']);
        $this->assign("thread_head",$thread['head_list']);
        $this->assign("page_banner",$thread['banner']);
        //$this->assign("mid",$m_id);
        return $this->fetch('search');
    }
}